package indi.gao.redis;


import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c)2019$</p>
 * <p>Company: Tope</p>
 * <P>Created Date :2019$-08$-19$</P>
 * <P>@version 1.0</P>
 */
class Person {

    public Person(String name) {
        this.name = name;
    }

    public Person() {
    }

    private String name;
    public Long age;
    public static String ID;
}

class TestFieldToString {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException {

        //  得到现在的 修饰符名 和 字段类型
        Field[] fields = Person.class.getDeclaredFields();
        System.out.println(fields[0].toString());
//        字段类型
        int mod = fields[0].getModifiers();
        System.out.println(Modifier.toString(mod));
        // 判断是否为字private
        //  public static boolean isPrivate(int mod) {
        //  return (mod & PRIVATE) != 0;

        System.out.println(Modifier.isPrivate(mod) + " is private");
//        通过反射实例化对象(调用无参构造函数)
        Person s = Person.class.newInstance();
        /**
         * 调用有参构造函数实例化对象
         */
        Class<?> s1 = Class.forName("indi.gao.redis.Person");
        Constructor<?> constructor = s1.getConstructor(String.class);
        Person person = (Person) constructor.newInstance("高雷");
        System.out.println(person);

        System.out.println(s1.toString() + "class For name");
        //8进制转10进制
        System.out.println(Integer.valueOf("77777", 8));
        //10进制转8进制
        System.out.println(Integer.toString(311, 8));
        System.out.println(8 & 0X000006);
    }
}

